import { createRouter, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import type { App } from 'vue'
import { Layout, getParentLayout } from '@/utils/routerHelper'
import { useI18n } from '@/hooks/web/useI18n'
import { NO_RESET_WHITE_LIST } from '@/constants'
import homeicon from '@/assets/imgs/logo.png'
const { t } = useI18n()

export const constantRouterMap: AppRouteRecordRaw[] = [
  {
    path: '/',
    component: Layout,
    redirect: '/home/home',
    name: 'Root',
    meta: {
      hidden: true
    }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home1/home1',
    name: 'Root',
    meta: {
      hidden: true
    }
  },
  {
    path: '/screen',
    component: () => import('@/views/Screen/Screen.vue'),
    meta: { title: '大屏', icon: 'ic:baseline-airplay', newWindow: true, hidden: true },
    name: 'screen'
  },
  // {
  //   path: '/redirect',
  //   component: Layout,
  //   name: 'Redirect',
  //   children: [
  //     {
  //       path: '/redirect/:path(.*)',
  //       name: 'Redirect',
  //       component: () => import('@/views/Redirect/Redirect.vue'),
  //       meta: {}
  //     }
  //   ],
  //   meta: {
  //     hidden: true,
  //     noTagsView: true
  //   }
  // },
  {
    path: '/assessment',
    component: Layout,
    name: 'assessment',
    meta: {
      title: '考核结果',
      icon: 'ic:baseline-grading',
      noTagsView: true,
      noCache: true,
      hidden: true,
      canTo: true
    },
    children: [
      {
        path: 'assessment',
        component: () => import('@/views/SuperviseCenter/Assessment.vue'),
        name: 'assessment',
        meta: {
          title: '考核结果',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/addevalate',
    component: Layout,
    name: 'addevalate',
    meta: {
      title: '新增评价',
      icon: 'ic:baseline-grading',
      noTagsView: true,
      noCache: true,
      hidden: true,
      canTo: true
    },
    children: [
      {
        path: 'addevalate',
        component: () => import('@/views/examination/components/CourseEvaluateWrite.vue'),
        name: 'addevalate',
        meta: {
          title: '新增评价',
          hidden: true
        }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/Login/Login.vue'),
    name: 'Login',
    meta: {
      hidden: true,
      title: '登录',
      noTagsView: true
    }
  },
  {
    path: '/personal',
    component: Layout,
    redirect: '/personal/personal-center',
    name: 'Personal',
    meta: {
      title: '个人中心',
      hidden: true,
      canTo: true
    },
    children: [
      {
        path: 'personal-center',
        component: () => import('@/views/Personal/PersonalCenter/PersonalCenter.vue'),
        name: 'PersonalCenter',
        meta: {
          title: '个人中心',
          hidden: true,
          canTo: true
        }
      }
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/Error/404.vue'),
    name: 'NoFind',
    meta: {
      hidden: true,
      title: '404',
      noTagsView: true
    }
  }
]

export const asyncRouterMap: AppRouteRecordRaw[] = [
  {
    path: '/home',
    component: Layout,
    redirect: '/home/home',
    name: 'home',
    meta: { icon: 'ic:baseline-menu-book' },
    children: [
      {
        path: 'home',
        component: () => import('@/views/Dashboard/Analysis.vue'),
        name: 'home',
        meta: {
          title: '首页',
          icon: 'ic:baseline-menu-book',
          // imgsrc: '@/assets/imgs/logo.png',
          noCache: true
        }
      }
      // {
      //   path: 'home',
      //   component: () => import('@/views/homepage/homepage.vue'),
      //   name: 'home',
      //   meta: {
      //     title: '首页',
      //     icon: 'ic:baseline-menu-book',
      //     noCache: true
      //   }
      // }
    ]
  },
  {
    path: '/home1',
    component: Layout,
    redirect: '/home1/home1',
    name: 'home1',
    meta: { icon: 'ic:baseline-menu-book' },
    children: [
      {
        path: 'home1',
        component: () => import('@/views/splitScreen/index.vue'),
        name: 'home1',
        meta: {
          title: '首页',
          icon: 'ic:baseline-menu-book',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/course',
    component: Layout,
    name: 'course',
    meta: {
      title: '课程管理',
      icon: 'ic:baseline-monitor',
      alwaysShow: true
    },
    children: [
      {
        path: 'coursemanagement',
        component: () => import('@/views/course/coursemanagement.vue'),
        name: 'coursemanagement',
        meta: {
          title: '课程管理',
          icon: 'ant-design:database-outlined',
          noCache: true
        }
      },
      {
        path: 'coursetype',
        component: () => import('@/views/course/coursetype.vue'),
        name: 'coursetype',
        meta: {
          title: '课程分类',
          icon: 'ic:baseline-auto-awesome-mosaic'
        }
      },
      {
        path: 'coursetag',
        component: () => import('@/views/course/coursetag.vue'),
        name: 'coursetag',
        meta: {
          title: '课程标签',
          icon: 'ic:baseline-auto-awesome-motion'
        }
      }
    ]
  },
  {
    path: '/courseplan',
    component: Layout,
    name: 'courseplan',
    meta: {
      title: '培训管理',
      icon: 'ant-design:dashboard-filled',
      alwaysShow: true
    },
    children: [
      {
        path: 'courseplan',
        component: () => import('@/views/courseplan/courseplan.vue'),
        name: 'courseplan',
        meta: {
          title: '培训记录',
          icon: 'ic:baseline-campaign'
        }
      },
      {
        path: 'planevaluate',
        component: () => import('@/views/courseplan/planevaluate.vue'),
        name: 'planevaluate',
        meta: {
          title: '培训评价',
          icon: 'ic:baseline-campaign'
        }
      }
    ]
  },
  {
    path: '/examination',
    component: Layout,
    name: 'examination',
    meta: {
      title: '考试管理',
      icon: 'ic:baseline-fax',
      alwaysShow: true
    },
    children: [
      {
        path: 'examinationlog',
        component: () => import('@/views/examination/examinationlog.vue'),
        name: 'examinationlog',
        meta: {
          title: '考试记录',
          icon: 'ic:baseline-insert-chart-outlined'
        }
      },
      {
        path: 'evaluate',
        component: () => import('@/views/examination/evaluate.vue'),
        name: 'evaluate',
        meta: {
          title: '考试评价',
          icon: 'ic:outline-directions-railway'
        }
      },
      {
        path: 'scoreCriteria',
        component: () => import('@/views/courseplan/ScoreCriteria.vue'),
        name: 'scoreCriteria',
        meta: {
          title: '评分规则',
          icon: 'ic:baseline-campaign'
        }
      }
    ]
  },
  {
    path: '/datastatistics',
    component: Layout,
    name: 'datastatistics',
    meta: {
      title: '数据统计',
      icon: 'ic:baseline-filter',
      alwaysShow: true
    },
    children: [
      {
        path: 'courseanalysis',
        component: () => import('@/views/datastatistics/CourseAnalysis.vue'),
        name: 'courseanalysis',
        meta: {
          title: '课程分析',
          icon: 'ic:baseline-event-note'
        }
      },
      {
        path: 'teacherschedule',
        component: () => import('@/views/datastatistics/teacherschedule.vue'),
        name: 'teacherschedule',
        meta: {
          title: '老师授课分析表',
          icon: 'ic:baseline-perm-contact-calendar'
        }
      },
      {
        path: 'courseschedule',
        component: () => import('@/views/datastatistics/courseschedule.vue'),
        name: 'courseschedule',
        meta: {
          title: '课程培训情况表',
          icon: 'ic:baseline-list-alt'
        }
      },
      {
        path: 'examinationschedule',
        component: () => import('@/views/datastatistics/examinationschedule.vue'),
        name: 'examinationschedule',
        meta: {
          title: '考试情况表',
          icon: 'ic:baseline-local-library'
        }
      }
    ]
  },
  {
    path: '/datacenter',
    component: Layout,
    name: 'datacenter',
    meta: {
      title: '数据中心',
      icon: 'ic:baseline-monitor',
      alwaysShow: true
    },
    children: [
      {
        path: 'videoretrieval',
        component: () => import('@/views/DataCenter/VideoRetrieval.vue'),
        name: 'videoretrieval',
        meta: {
          title: '视频检索',
          icon: 'ic:baseline-missed-video-call'
        }
      },
      {
        path: 'imgretrieval',
        component: () => import('@/views/DataCenter/IMGRetrieval.vue'),
        name: 'imgretrieval',
        meta: {
          title: '图像检索',
          icon: 'ic:baseline-cast-connected'
        }
      },
      {
        path: 'audioretrieval',
        component: () => import('@/views/DataCenter/AudioRetrieval.vue'),
        name: 'audioretrieval',
        meta: {
          title: '音频检索',
          icon: 'ic:baseline-music-video'
        }
      },
      {
        path: 'logretrieval',
        component: () => import('@/views/DataCenter/LogRetrieval.vue'),
        name: 'logretrieval',
        meta: {
          title: '日志检索',
          icon: 'ic:baseline-aod'
        }
      },
      {
        path: 'peccancy',
        component: () => import('@/views/DataCenter/Peccancy.vue'),
        name: 'peccancy',
        meta: {
          title: '违章记录',
          icon: 'ic:baseline-mark-unread-chat-alt'
        }
      },
      {
        path: 'rectification',
        component: () => import('@/views/DataCenter/Rectification.vue'),
        name: 'rectification',
        meta: {
          title: '整改记录',
          icon: 'ic:baseline-assist-walker'
        }
      },
      {
        path: 'reinspection',
        component: () => import('@/views/DataCenter/ReInspection.vue'),
        name: 'reinspection',
        meta: {
          title: '复检记录',
          icon: 'ic:baseline-blind'
        }
      },
      {
        path: 'analysis',
        component: () => import('@/views/DataCenter/Analysis.vue'),
        name: 'analysis',
        meta: {
          title: '统计分析',
          icon: 'ic:baseline-post-add'
        }
      },
      {
        path: 'usersanalysis',
        component: () => import('@/views/DataCenter/usersAnalysis.vue'),
        name: 'usersanalysis',
        meta: {
          title: '用户考核',
          icon: 'ic:baseline-diversity-3'
        }
      }
    ]
  },
  {
    path: '/supervisecenter',
    component: Layout,
    name: 'supervisecenter',
    meta: {
      title: '监督中心',
      icon: 'ic:baseline-fax',
      alwaysShow: true
    },
    children: [
      {
        path: 'evaluation',
        component: () => import('@/views/SuperviseCenter/Evaluation.vue'),
        name: 'evaluation',
        meta: {
          title: '考评核查总览',
          icon: 'ic:baseline-insert-chart-outlined'
        }
      },
      {
        path: 'randomcheck',
        component: () => import('@/views/SuperviseCenter/RandomCheck.vue'),
        name: 'randomcheck',
        meta: {
          title: '随机抽查',
          icon: 'ic:outline-directions-railway'
        }
      },
      {
        path: 'targetedcheck',
        component: () => import('@/views/SuperviseCenter/TargetedCheck.vue'),
        name: 'targetedcheck',
        meta: {
          title: '定向抽查',
          icon: 'ic:outline-directions-transit'
        }
      },
      {
        path: 'assessmentresults',
        component: () => import('@/views/SuperviseCenter/AssessmentResults.vue'),
        name: 'assessmentresults',
        meta: {
          title: '考核结果',
          icon: 'ic:baseline-grading'
        }
      }
    ]
  },
  {
    path: '/operatecenter',
    component: Layout,
    name: 'operatecenter',
    meta: {
      title: '运维中心',
      icon: 'ant-design:dashboard-filled',
      alwaysShow: true
    },
    children: [
      {
        path: 'notice',
        component: () => import('@/views/OperateCenter/Notice.vue'),
        name: 'notice',
        meta: {
          title: '公告',
          icon: 'ic:baseline-campaign'
        }
      },
      {
        path: 'oplogs',
        component: () => import('@/views/OperateCenter/OPLogs.vue'),
        name: 'oplogs',
        meta: {
          title: '操作日志',
          icon: 'ic:baseline-speaker-notes'
        }
      },

      {
        path: 'operationmonitoring',
        component: () => import('@/views/OperateCenter/OperationMonitoring.vue'),
        name: 'operationmonitoring',
        meta: {
          title: '运行监控',
          icon: 'ic:baseline-screenshot-monitor'
        }
      },
      {
        path: 'assets',
        component: () => import('@/views/OperateCenter/AssetsStatistics.vue'),
        name: 'assets',
        meta: {
          title: '资产统计',
          icon: 'ic:outline-cabin'
        }
      },

      {
        path: 'systemmanage',
        component: () => import('@/views/OperateCenter/SystemManage.vue'),
        name: 'systemmanage',
        meta: {
          title: '系统任务管理',
          icon: 'ic:baseline-storage'
        }
      }
    ]
  },
  {
    path: '/settingcenter',
    component: Layout,
    name: 'settingcenter',
    meta: {
      title: '配置中心',
      icon: 'ic:outline-build',
      alwaysShow: true
    },
    children: [
      {
        path: 'workmanage',
        component: () => import('@/views/SettingCenter/workmanage.vue'),
        name: 'workmanage',
        meta: {
          title: '采集站管理',
          icon: 'ic:baseline-sports-mma'
        }
      },
      {
        path: 'collectionmanage',
        component: () => import('@/views/SettingCenter/CollectionManage.vue'),
        name: 'collectionmanage',
        meta: {
          title: '采集站管理',
          icon: 'ic:baseline-sports-mma'
        }
      },
      {
        path: 'departmentmanage',
        component: () => import('@/views/SettingCenter/DepartmentManage.vue'),
        name: 'departmentmanage',
        meta: {
          title: '部门管理',
          icon: 'ic:baseline-manage-accounts'
        }
      },
      {
        path: 'usermanage',
        component: () => import('@/views/SettingCenter/UserManage.vue'),
        name: 'usermanage',
        meta: {
          title: '用户管理',
          icon: 'ic:baseline-people-alt'
        }
      },
      {
        path: 'assetsmanage',
        component: () => import('@/views/OperateCenter/AssetsManage.vue'),
        name: 'assetsmanage',
        meta: {
          title: '设备管理',
          icon: 'ic:baseline-stay-current-landscape'
        }
      },
      {
        path: 'role',
        component: () => import('@/views/SettingCenter/Role.vue'),
        name: 'role',
        meta: {
          title: '角色管理',
          icon: 'ic:baseline-perm-identity'
        }
      },
      {
        path: 'authorization',
        component: () => import('@/views/SettingCenter/Authorization.vue'),
        name: 'authorization',
        meta: {
          title: '权限管理',
          icon: 'ic:baseline-question-answer'
        }
      },
      {
        path: 'workertype',
        component: () => import('@/views/SettingCenter/WorkerType.vue'),
        name: 'workertype',
        meta: {
          title: '作业类型管理',
          icon: 'ic:baseline-rowing'
        }
      },
      {
        path: 'problemtype',
        component: () => import('@/views/SettingCenter/ProblemType.vue'),
        name: 'problemtype',
        meta: {
          title: '违章类型管理',
          icon: 'ic:baseline-person-add-disabled'
        }
      },

      {
        path: 'upgradepackage',
        component: () => import('@/views/OperateCenter/UpgradePackage.vue'),
        name: 'upgradepackage',
        meta: {
          title: '升级包管理',
          icon: 'ic:baseline-browser-updated'
        }
      },
      {
        path: 'menu',
        component: () => import('@/views/SettingCenter/Menu.vue'),
        name: 'menu',
        meta: {
          title: '菜单管理',
          icon: 'ic:baseline-dehaze'
        }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  strict: true,
  routes: constantRouterMap as RouteRecordRaw[],
  scrollBehavior: () => ({ left: 0, top: 0 })
})

export const resetRouter = (): void => {
  console.log('resetRouter------', router.getRoutes())
  router.getRoutes().forEach((route) => {
    const { name } = route
    if (name && !NO_RESET_WHITE_LIST.includes(name as string)) {
      router.hasRoute(name) && router.removeRoute(name)
    }
  })
}

export const setupRouter = (app: App<Element>) => {
  app.use(router)
}

export default router
